<include file="Index/_meta" />
<body>
<style>
    .box{
        margin-top: 20px;
        margin-left: 20px;
        box-shadow: none;
    }
    .sum{
        float: right;
        margin-right: 20px;
        line-height: 32px;
    }
    .quanxian{
        display: inline-block;
        width: 200px;
    }
    .addquanxian{
        display: inline-block;
        float: left;
    }
    .juzhong{
        width: 270px;
        margin: 0 auto;
    }
    .refresh{
        display: inline-block;
        float: right;
        margin-right: 20px;
    }
</style>
<div class="box">
    <button class="layui-btn layui-btn-normal addquanxian">添加角色</button>
    <button class="layui-btn layui-btn-normal refresh" onclick="refresh()" title="刷新"><i class="layui-icon">&#x1002;</i></button>
    <div class="layui-input-block juzhong">
        <input type="text" name="title" autocomplete="off" placeholder="请输入角色名称" class="layui-input quanxian">
        <button class="layui-btn layui-btn-normal"><i class="layui-icon">&#xe615;</i></button>
    </div>

    <span class="sum">共有数据：<strong><?php echo $count ?></strong> 条</span>
</div>
<div class="layui-fluid">
    <table class="layui-table" style="text-align: center">

        <thead>
        <tr>
            <th style="text-align: center" width="8%">ID</th>
            <th style="text-align: center" width="30%">角色名称</th>
            <th style="text-align: center" width="27%">用户列表</th>
            <th style="text-align: center" width="27%">描述</th>
            <th style="text-align: center" width="8%">操作</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($data as $v){?>
        <tr>
            <td><?php echo $v['id'] ?></td>

            <td style="text-align: left"><?php echo str_repeat('&nbsp;',8*$v['level']),$v['level']==0?'':'|',str_repeat('-',8*$v['level']),$v['role_name'] ?></td>
            <td><?php echo $v['module_name'] ?></td>
            <td><?php echo $v['controller_name'] ?></td>
            <td>
                <a href="javascript:void (0);" onclick="admin_permission_edit(<?php echo $v['id']?>)"><i class="layui-icon">&#xe642;</i></a>
                <!--<a href="javascript:void (0);" onclick="admin_permission_del(this,<?php echo $v['id']?>)"><i class="layui-icon">&#xe640;</i></a>-->
            </td>
        </tr>
        <?php }?>
        <!--<tr>-->
            <!--<td>张爱玲</td>-->
            <!--<td>汉族</td>-->
            <!--<td>1920-09-30</td>-->
            <!--<td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>-->
            <!--<td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>-->
            <!--<td>-->
                <!--<a href=""><i class="layui-icon">&#xe642;</i></a>-->
                <!--<a href=""><i class="layui-icon">&#xe640;</i></a>-->
            <!--</td>-->
        <!--</tr>-->
        </tbody>
    </table>
</div>

<script type="text/javascript">
    layui.use(['layer'],function () {
        var layer = layui.layer;
        $('.addquanxian').click(function () {
            layer.open({
                type: 2,
                title: '添加角色',
                shadeClose: true,
                shade: 0.5,
                maxmin: true, //开启最大化最小化按钮
                area: ['850px', '500px'],
                content: '/index.php/home/role/add'
            });
        })
    });

    //页面刷新
    function refresh() {
        location.replace(location.href);
    }

    //编辑
    function admin_permission_edit(id) {
        layer.open({
            type: 2,
            title: '编辑角色',
            shadeClose: true,
            shade: 0.5,
            maxmin: true, //开启最大化最小化按钮
            area: ['850px', '500px'],
            content: '/index.php/home/role/edit?id='+id
        })
    }

    //删除
    function admin_permission_del(obj,id){
        layer.confirm('角色删除须谨慎，确认要删除吗？',function(index){
            var url = "/index.php/Home/role/del";
            var data = {id:id};
            $.post(url,data,function(result){
                if(result.status == 1){
                    $(obj).parents("tr").remove();
                    layer.msg(result.message,{icon:1,time:1000});
                }
                if(result.status == 0){
                    layer.msg(result.message);
                }
            },"JSON");
        });
    }
</script>

</body>